﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using Model;
using UI.Lib.Factory;
using Components;
using System.Collections;
using Com.Seezt.Skins;

namespace UI.CommonForm
{
    public partial class FrmResizeWidth : BaseForm
    {
        private string _pageName = ""; //当前页面名称
        private string _ctl = string.Empty;

        public FrmResizeWidth(string title, string pageName, string ctl)
        {
            InitializeComponent();

            this._pageName = pageName;
            this._ctl = ctl;
            this.Text = title + " - 宽度设置";

            _pageInit();
        }

        public bool IsReloadWIn = false;

        private void _pageInit()
        {
            Hashtable tb = new Hashtable();
            tb["ctl"] = this._ctl;
            tb["pagename"] = this._pageName;

            DataTable dtLayout = CommonHelper.Entity.ExecFun("getpagesetting", tb);
            tb = null;

            if (dtLayout == null)
            {
                MessageBox.Show("加载出错～");
                return;
            }

            this.dgvMain.DataSource = dtLayout;
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this.Size = new Size(500, 400);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DataTable dtldata = SetDtlSaveData();
            string errmsg = CommonHelper.Entity.SaveDtl("Sys5a01Manager$SaveData", null, "M", dtldata, null); //调用服务器的保存方法

            if (!string.IsNullOrEmpty(errmsg))
            {
                MsgBox.ShowErrorMsg(this, errmsg);
                return;
            }

            IsReloadWIn = true;
            this.Close();
        }

        protected virtual DataTable SetDtlSaveData()
        {
            int rowCount = this.dgvMain.Rows.Count;

            this.dgvMain.EndEdit();
            DataTable dt = new DataTable();
            dt.TableName = "DTLDATA";
            DataColumn dc;
            for (int i = 0; i < dgvMain.Columns.Count; i++)
            {
                dc = new DataColumn();
                dc.ColumnName = dgvMain.Columns[i].Name.ToString();
                dt.Columns.Add(dc);
            }
            for (int j = 0; j < dgvMain.Rows.Count; j++)
            {
                DataRow dr = dt.NewRow();
                for (int x = 0; x < dgvMain.Columns.Count; x++)
                {
                    dr[x] = dgvMain.Rows[j].Cells[x].Value;
                }

                tbNewWidth[dr["colname"]] = dr["columnwidth"];

                dt.Rows.Add(dr);
            }

            return dt;
        }

        private Hashtable tbNewWidth = new Hashtable();

        public Hashtable colsWidth { get { return tbNewWidth; } }
    }
}
